//
//  MainViewController.swift
//  SinaWeibo
//
//  Created by yhlun on 15/11/8.
//  Copyright © 2015年 yhlun. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
    
    
    @objc private func composeDidClick(){
    
        print(__FUNCTION__)
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        
        
        //由于tabbar 是只读 不能直接操作 如果要修改 可以使用KVC
        
        let maintabBar = MainTabBar()
        
        //kvc 赋值
        setValue(maintabBar, forKey: "tabBar")
        
        

        //添加子视图控制器
        addChildViewControllers()
        
        print(tabBar.classForCoder)
        
        //设置点击事件
        maintabBar.composeBtn.addTarget(self, action: "composeDidClick", forControlEvents: UIControlEvents.TouchUpInside)
    }
    
    
    
   private func addChildViewControllers() {
    
        addChildViewController(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(ProfileTableViewController(), title: "我", imageName: "tabbar_profile")
    }
    
    private func addChildViewController(vc: UIViewController ,title: String, imageName: String) {
    
        
        //添加导航控制器
        let nav = UINavigationController(rootViewController: vc)
        
        vc.title = title
        vc.tabBarItem.image  = UIImage(named: imageName)
        
        addChildViewController(nav)
        
    }
    
    


}
